let _runnerElem;
export const initRuner = (runnerElem) => {
  _runnerElem = runnerElem
}

export const startRuner = () => {
  _runnerElem.start()
}

export const stopRuner = () => {
  _runnerElem.stop()
}

// 树的关键帧
export const runnerFrames = [
  {
    src: "/assets/images/runner1.png",
  },
  {
    src: "/assets/images/runner2.png",
  },
  {
    src: "/assets/images/runner3.png",
  },
]

export const jump = (minTime, cb) => {
  const keyframes = [
    {
      transformOrigin: "50% 50%",
      time: 0,
      transform: {
        translateY: '0',
      },
    },
    {
      transformOrigin: "50% 50%",
      time: 50,
      transform: {
        translateY: "-150",
      },
    },
    {
      transformOrigin: "50% 50%",
      time: 100,
      transform: {
        translateY: "0",
      },
    }
  ]
  const options = {
    // 1.5 是难度系数
    duration: 1500, //minTime * 1.5,
    // 抛物线模拟
    easing: 'cubic-bezier(0.140, 0.640, 0.710, 0.240)',
    delay: 0
  }
  let animation = _runnerElem.animate(keyframes, options)
  animation.onfinish = () => {
    cb()
  }
  animation.play()
}